package com.mall507.fivepeaks.activity.mine;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.hzh.frame.comn.annotation.ViewInject;
import com.hzh.frame.comn.callback.HttpCallBack;
import com.hzh.frame.core.BaseSP;
import com.hzh.frame.core.HttpFrame.BaseHttp;
import com.hzh.frame.ui.activity.BaseUI;
import com.mall507.comn.model.User;
import com.mall507.comn.tools.UserTools;
import com.mall507.fivepeaks.R;

import org.json.JSONException;
import org.json.JSONObject;

@Route(path = "/mine/SettingEditsignatureUI")
public class SettingEditsignatureUI extends BaseUI implements View.OnClickListener {
    @ViewInject(R.id.signature) //用户个性签名
    EditText signature;
    User mUser;
    
    @Override
    protected void onCreateBase() {
        mUser= UserTools.getInstance().getUser();
        setContentView(R.layout.ui_mine_setting_editsignature);
        getTitleView().setContent("修改个性签名");
        getTitleView().setRightContent("完成");
        signature.setText(getIntent().getStringExtra("signature"));
        getTitleView().setRightOnclickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                editSignature();
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            
        }
    }
    
    private void editSignature(){
        BaseHttp.getInstance().query("Me/Edit", getParams(), new HttpCallBack() {
            @Override
            public void onSuccess(JSONObject response) {
                if (response.optInt("code") == 200){
                    mUser.setPersonalSign(signature.getText().toString().trim());
                    UserTools.getInstance().updUser(mUser);
                    finish();
                }
                alert(response.optString("msg"));
                super.onSuccess(response);
            }
        });
    }

    protected JSONObject getParams() {
        JSONObject params = new JSONObject();
        try {
            params.put("type", 4);
            params.put("sign", signature.getText().toString().trim());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return params;
    }
}
